import {
    user_control, user_register, user_cancel,
    user_getbyid, user_update, secondary, batchdelete,
    company, batchdcreate, batchdselect, batchdupdate,
    batchdsearch, modification, management, character,
    roleassignment, changepassword, managementop, additroles,
    permissionsdelete, getRoleList, partgetbyid
} from '../../api/table'

const table = {
    state: {
        list: [], // 用户数据
        alter_password: null, // 修改密码
        rolesparent: [], // 父级权限
    },
    mutations: {
        SET_LIST: (state, list) => {
            state.list = list
        },
        SET_ALTER_PASSWORD: (state, alter_password) => {
            state.alter_password = alter_password
        },
        SET_ROLESPARENT: (state, rolesparent) => {
            state.rolesparent = rolesparent
        }
    },
    actions: {
        // 用户表格数据
        User_control({ commit, state }, searchPara) {
            return new Promise((resolve, reject) => {
                user_control(searchPara).then(data => {
                    commit("SET_LIST", data.list);
                    // console.log("cIdclock: "+JSON.stringify(cIdclock))
                    resolve(data)
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 新增用户
        User_register({ commit, state }, increased) {
            return new Promise((resolve, reject) => {
                user_register(increased).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 删除用户
        User_cancel({ commit, state }, cancel) {
            return new Promise((resolve, reject) => {
                user_cancel(cancel).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 获取编辑用户信息
        User_getbyid({ commit, state }, compile) {
            return new Promise((resolve, reject) => {
                user_getbyid(compile).then(data => {
                    commit("SET_ALTER_PASSWORD", data.password);
                    resolve(data)
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 编辑用户
        User_update({ commit, state }, editor) {
            return new Promise((resolve, reject) => {
                user_update(editor).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 二级管理员测试
        Secondary({ commit, state }) {
            return new Promise((resolve, reject) => {
                secondary().then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error);
                })
            })
        },
        // 批量删除数据
        Batchdelete({ commit, state }, batch) {
            return new Promise((resolve, reject) => {
                batchdelete(batch).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error);
                })
            })
        },
        // 新增用户角色
        Batchdcreate({ commit, state }, create) {
            return new Promise((resolve, reject) => {
                batchdcreate(create).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error);
                })
            })
        },
        // 用描述查询用户角色
        Batchdselect({ commit, state }, select) {
            return new Promise((resolve, reject) => {
                batchdselect(select).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error);
                })
            })
        },
        // 获取编辑用户角色信息
        Partgetbyid({ commit, state }, part) {
            return new Promise((resolve, reject) => {
                partgetbyid(part).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error);
                })
            })
        },
        // 编辑用户角色
        Batchdupdate({ commit, state }, account) {
            return new Promise((resolve, reject) => {
                batchdupdate(account).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error);
                })
            })
        },
        // 获取当前角色的权限
        Batchdsearch({ commit, state }, seek) {
            return new Promise((resolve, reject) => {
                batchdsearch(seek).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error);
                })
            })
        },
        // 用户权限修改
        Modification({ commit, state }, authority) {
            return new Promise((resolve, reject) => {
                modification(authority).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 新增用户权限
        Additroles({ commit, state }, addroles) {
            return new Promise((resolve, reject) => {
                additroles(addroles).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 批量删除权限
        Permissionsdelete({ commit, state }, permissiondelete) {
            return new Promise((resolve, reject) => {
                permissionsdelete(permissiondelete).then(data => {
                    resolve(data)
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 公司管理测试
        Company({ commit, state }) {
            return new Promise((resolve, reject) => {
                company().then(data => {
                    resolve(data);
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 权限管理
        Management({ commit, state }, paging) {
            return new Promise((resolve, reject) => {
                management(paging).then(data => {
                    commit("SET_ROLESPARENT", data.list)
                    resolve(data);
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 获取所有权限
        managementop({ commit, state }) {
            return new Promise((resolve, reject) => {
                managementop().then(data => {
                    resolve(data);
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 所有角色
        Character({ commit, state }, rolest) {
            return new Promise((resolve, reject) => {
                character(rolest).then(data => {
                    resolve(data);
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 角色的分配
        Roleassignment({ commit, state }, assignment) {
            return new Promise((resolve, reject) => {
                roleassignment(assignment).then(data => {
                    resolve(data);
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 修改密码
        Changepassword({ commit, state }, pawd) {
            return new Promise((resolve, reject) => {
                changepassword(pawd).then(data => {
                    resolve(data);
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 获取用户已有的角色
        GetRoleList({ commit, state }, rolelist) {
            return new Promise((resolve, reject) => {
                getRoleList(rolelist).then(data => {
                    resolve(data);
                }).catch(error => {
                    reject(error)
                })
            })
        }
    }
}

export default table;